package com.retlife.tvshow.serial_port.bike;

public class Util
{
    //使用kotlin写可能会出错
    public static int crc(byte[] bytes){
        int crc = 0xffff;
        for (int i = 3;i<bytes.length-2;i++){
            crc = crc^(bytes[i]&0xff);
            for (int j = 0;j<8;j++){
                if ((crc&0x0001)==0x0001){
                    crc = crc>>1;
                    crc = crc^0xA001;
                }else{
                    crc = crc>>1;
                }
            }
        }
        return crc;
    }

    public static int commandCode(byte[] bytes){

        return (((bytes[3]&0xff)<<8)|(bytes[4]&0xff))&0xffff;
    }


}
